package main

import "sync"

type Tool struct {
	values int
}

// 建立私有变量
var instance *Tool
var lock sync.Mutex

// 获取单例对象的方法
func GetInstance() *Tool {
	lock.Lock()
	defer lock.Unlock()
	if instance == nil {
		instance = new(Tool)
	}
	return instance
}

func GetInstance2() *Tool {
	if instance == nil {
		lock.Lock()
		if instance == nil {
			instance = new(Tool)
		}
		lock.Unlock()
	}
	return instance
}

var once sync.Once

func GetInstance3() *Tool {
	once.Do(func() {
		instance = new(Tool)
	})
	return instance
}
